﻿/*******************************************************************************
 * Copyright © 2017 FriendStar.Framework 版权所有
 * Author: FZH
 * Description: FriendStar快速开发平台
 * Website：http://www.FriendStar.cn
*********************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using SqlSugarRepository;
using FriendStar.Code;
using FriendStar.Domain.Entity.MainData;
using FriendStar.Domain.IRepository.MainData;
using FriendStar.Repository.MainData;

namespace FriendStar.Application.MainData
{
    /// <summary>
    /// 数据表 BUS_SJ_Production 对应的数据应用功能类。
    /// </summary>
    public class ProductionApp
    {
        private static string UseUnit = Configs.GetValue("UseUnit");

        private IProductionRepository service = new ProductionRepository();
        private IProductionLVRepository serviceLV = new ProductionLVRepository();

        public List<ProductionLVEntity> GetList(Pagination pagination, string production, string spec, string pressClass)
        {
            var expression = ExtLinq.True<ProductionLVEntity>();
            if (!string.IsNullOrEmpty(production))
            {
                expression = expression.And(t => t.FProductionNO.Contains(production));
                expression = expression.Or(t => t.ProductionName.Contains(production));
            }
            if (!string.IsNullOrEmpty(spec))
            {
                expression = expression.And(t => t.ProductionSpec == spec);
            }
            if (!string.IsNullOrEmpty(pressClass))
            {
                expression = expression.And(t => t.PressClassNO == pressClass);
            }
            return serviceLV.FindList(expression, pagination);
        }

        public ProductionEntity GetForm(string keyValue)
        {
            return service.FindEntity(keyValue);
        }

        public void DeleteForm(string keyValue)
        {
            service.Delete(t => t.FProductionID == keyValue);
        }

        public void SubmitForm(ProductionEntity entity, string keyValue)
        {
            if (!string.IsNullOrEmpty(keyValue))
            {
                service.Update(entity);
            }
            else
            {
                entity.FProductionID = Common.GuId();
                entity.UseUnit = UseUnit;
                service.Insert(entity);
            }
        }
    }
}